--
-- Author: ping.wang
-- Date: 2019-05-20 16:32:43
--
-- RenamePlayerView
--

local fileName = string.getModeName(...)
local ClassRef = class(fileName, app.mvc.ViewBase)

ClassRef.VIEW_ROOT_RES = Res.RenamePlayerScene

function ClassRef:init()
    self._ui.Button_back:addClickEventListener(function()
        self:closeView()
    end)
    self._ui.Button_quxiao:addClickEventListener(function()
        self:closeView()
    end)
    self._editText = display.replaceTextFieldWithEditBox(self._ui.Panel_input:findChild("TextField"))
    --self._editText:registerScriptEditBoxHandler(onEditCallback)
    self._ui.Button_queding:addClickEventListener(function()
        local str = self._editText:getText()
        if str and #str > 0 then

            local contentStr = string.format(L("rename2"),L("itemname_75100100"),str)

            local confirmDialog = display.newConfirmDialog(contentStr,
                function()
                    executeFunc(self._onOperate, "renamePlayer", str)
                    self:closeView()
                end,nil)
            confirmDialog:setConfirmText(L("tips_ok"))
            confirmDialog:setCancelText(L("tips_cancel"))
            --角色改名卡 此处要更换为富文本
            confirmDialog:replaceTextByRichText(self:getRichText(str,"#8132be"))

            UIHandler:addPopDialog(confirmDialog, 1, true)
        else
            display.pushToast(L("rename1"))
        end
    end)
end

function ClassRef:getRichText(name,colorStr)
    local defaults = {
        KEY_FONT_FACE = Res.font,
        KEY_FONT_SIZE = app:isLanguageEN() and 18 or 22,
        KEY_FONT_COLOR_STRING = "#2F0C04",
    }
    local str1 = display.getRichTextFontXml(name,colorStr,22)
    local str = string.format(L("rename2"),L("itemname_75100100"),str1)

    local richText = ccui.RichText:createWithXML( str, defaults )
    return richText
end

return ClassRef
